<template>
	<view class="orders">
		<view class="list" v-if='list.length'>
			<view class="line" v-for="(item,index) in list" :key='index' >
				<view class="orderNo dFlex jBetween_aCenter">
					<text class="num">订单编号 {{item.order_number}}</text>
					<view class="odStatus">
						<text style="color: #FF3B2F;" v-if='item.order_status=="1"'>待支付</text>
						<text style="color: #FF7D2F;" v-if='item.order_status=="2"'>派单中</text>
						<text style="color: #1BC447;" v-if='item.order_status=="3"'>待上门</text>
						<text style="color: #1664FF;" v-if='item.order_status=="4"'>进行中</text>
						<text style="color: #999999;" v-if='item.order_status=="5"'>已完成</text>
					</view>
				</view>
				<view class="shops">
					<view class="shopOne dFlex jStart_aStart" v-for="(item2,index2) in item.products" :key='index2'>
						<view class="shopImg imgPublic">
							<image :src="item2.list_img"></image>
						</view>
						<view class="shopInfo">
							<view class="shopName">{{item2.product_name}}</view>
							<view class="way">清洗方式:{{item2.order_type == '1'?'免拆清洗':'拆装清洗'}}</view>
							<view class="guige">洗护规格:{{item2.specs_name}}</view>
							<view class="price">￥{{item2.sell_price}} X {{item2.num}}</view>
						</view>
					</view>
				</view>	
				<view class="result dFlex jBetween_aCenter">
					<view class="allPrice">合计:<text>￥{{item.product_total}}</text></view>
					<view class="allPrice">收益金额:<text>￥{{item.give_amount}}</text></view>
				</view>
			</view>
		</view>
		<view class='list empty imgPublic' v-else>
			<image src='../static/images/empty.png' mode='widthFix'></image>
		</view>
		<view class='seat'></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				identity:uni.getStorageSync('identify')?uni.getStorageSync('identify'):'1',
				status:'1',// 默认全部 1待付款 2待接单 3待上门 4进行中 5已完成
				page:1,
				load:false,
				list:[],
			};
		},
		onLoad(e){
			console.log(e);
			this.status = e.status > 0?e.status:'1';
			this.page = 1;
			this.initList();
		},
		onReachBottom() {
			if(this.load){
				this.load = false;
				this.page++;
				this.initList();
			}
		},
		onShareAppMessage() {
			return{
				title:'洗匣士~您的家居窗帘清洗助手',
				path:'/pages/home?spreadId=' + (uni.getStorageSync('userId')?uni.getStorageSync('userId'):''),
				imageUrl:getApp().globalData.imgDomain+'public/logo.png',
				desc:'手机下单 | 专员取送 | 生态环保 | 轻奢洗护',
			}
		},
		onShareTimeline() {
			return{
				title:'洗匣士~您的家居窗帘清洗助手',
				path:'/pages/home?spreadId=' + (uni.getStorageSync('userId')?uni.getStorageSync('userId'):''),
				imageUrl:getApp().globalData.imgDomain+'public/logo.png',
				desc:'手机下单 | 专员取送 | 生态环保 | 轻奢洗护',
			}
		},
		methods:{
			initList(){
				this.tool.getData('Order/orderArea',{
					memberId:uni.getStorageSync('userId'),
					page:this.page
				}).then(res=>{
					// console.log(res);
					if(res){
						this.list = this.page == 1?res.list:this.list.concat(res.list);
						this.load = res.list.length>=10?true:false;
					}
				}).catch(err=>{
					console.log(err);
				})
			},
			// 查看订单详情
			lookDetail(orderId){
				if(this.identity == '1'){
					uni.navigateTo({
						url:'./orderDetail?oid='+orderId,
					})
				}else{
					uni.navigateTo({
						url:'../staging/orderDetail?orderId='+orderId
					})
				}
			},
			// 确认上门
			getDoor(orderId){
				uni.showModal({
					content:'确定接单师傅已上门？',
					success: (op) => {
						if(op.confirm){
							this.tool.getData('Order/orderChange',{
								orderId:orderId,
								type:'1'
							}).then(res=>{
								console.log(res);
								if(res){
									this.page = 1;
									this.initList();
								}
							}).catch(err=>{
								console.log(err);
							})
						}
					}
				})
			},
			// 确认完成
			sureFinish(){
				uni.showModal({
					content:'确定该订单没有问题并已完结？',
					success: (op) => {
						if(op.confirm){
							this.tool.getData('Order/orderChange',{
								orderId:orderId,
								type:'3'
							}).then(res=>{
								console.log(res);
								if(res){
									this.page = 1;
									this.initList();
								}
							}).catch(err=>{
								console.log(err);
							})
						}
					}
				})
			},
			// 取消订单
			cancelOrder(orderId){
				uni.showModal({
					content:'确定取消该订单？',
					success: (op) => {
						if(op.confirm){
							if(this.identity == '1'){
								this.tool.getData('Order/orderChange',{
									orderId:orderId,
									type:'2'
								}).then(res=>{
									console.log(res);
									if(res){
										uni.showToast({
											title:'订单已取消',
											icon:"none"
										})
										this.page = 1;
										this.initList();
									}
								}).catch(err=>{
									console.log(err);
								})
							}else{
								this.tool.getData('Store/orderChange',{
									type:1,
									orderId:orderId
								}).then(res=>{
									console.log(res);
									if(res){
										uni.showToast({
											title:'订单已取消',
											icon:"none"
										})
										this.page = 1;
										this.initList();
									}
								}).catch(err=>{
									console.log(err);
								})
							}
						}
					}
				})
			},
			// 支付订单
			payOrder(orderId){
				this.tool.getData('Order/orderPay',{
					orderId:orderId,
					pay_method:'2'
				}).then(res=>{
					console.log(res);
					if(res){
						uni.requestPayment({
							provider:'wxpay',
							timeStamp:res.weixin.timeStamp,
							nonceStr:res.weixin.nonceStr,
							package:res.weixin.package,
							signType:res.weixin.signType,
							paySign:res.weixin.paySign,
							success: () => {
								uni.showToast({
									title:'订单支付成功',
									icon:"success"
								})
								this.page = 1;
								this.initList();
							},
							fail:(err)=>{
								console.log(err);
								uni.showToast({
									title:'订单支付失败',
									icon:"none"
								})
							}
						})
						
					}
				}).catch(err=>{
					console.log(err);
				})
			},
			// 修改菜单
			changeMenu(status){
				this.status = status;
				this.page = 1;
				this.list = [];
				this.initList();
			}
		}
	}
</script>

<style lang="scss">
	.orders{
		width: 100%;
		padding: 0 4%;
		box-sizing: border-box;
		.list{
			width: 100%;
			margin-top: 12px;
			.line{
				width: 100%;
				border-radius: 2px;
				margin-bottom: 10px;
				background: white;
				padding:0 12px;
				box-sizing: border-box;
				.result{
					width: 100%;
					padding: 10px 0;
					border-top: 1px solid #EEEEEE;
					.allPrice{
						font-size: 12px;
						text{
							color: #FF3B2F;
							font-size: 14px;
						}
					}
				}
				.shops{
					width: 100%;
					.shopOne{
						width: 100%;
						padding: 8px 0;
						.shopInfo{
							flex: 1;
							.shopName{
								font-size: 15px;
							}
							.way,.guige{
								color: #999999;
								line-height: 22px;
								font-size: 12px;
							}
						}
						.shopImg{
							width: 82px;
							height: 82px;
							margin-right: 12px;
							image{
								height: 100%;
							}
						}
					}
				}
				.orderNo{
					width: 100%;
					padding: 10px 0;
					border-bottom: 1px solid #EEEEEE;
				}
			}
			.line:last-child{
				margin: 0;
			}
		}
	}
</style>
